import user from "../user.js";

export default {
  data() {
    return {
      settingList: user.settingList,
    }
  },
  template:/* html */`
    <div class="tab setting-tab">
      <div
        v-for="(setting,index) in settingList"
        :key="index"
      >
        <template v-if="setting.type === 'number'">
          <button
            class="flat"
            @click="set(setting)"
          >编辑</button>
          {{ setting.title }}：{{ setting.value }}
        </template>
      </div>
      <footer>
        Time Box
        <img src="favicon.ico">
        by FLY_Cloud
      </footer>
    </div>
  `,
  methods: {
    save() {
      user.save('settingList');
    },

    set(setting) {
      let res = window.prompt(setting.title);
      if (!isNaN(Number(res))) res = Number(res);
      if (setting.check(res))
        setting.value = res;
      this.save();
    }
  }
}
